-- CALC_SKY_ACTIVITY_RANK

-- 计算天空活动的积分排名
return function(activityId, score)
    if score <= 0 then
        return "--";
    end

    -- 总参与人数，这里取的是army表的总数，缩小一下
    local total = ServerStatusM.query("sky_city_num");
    if not total then
        total = 10000;
    else
        total = math.modf(0.5 * total);
    end

    -- 取出榜上最后一名玩家的积分、排名
    local list = TopM.getActivityTopData(activityId);
    local lastInfo = list[12];
    if not lastInfo then
        -- 没有信息不应该走到这里，保护一下
        return "--";
    end

    local lastScore = lastInfo["score"];
    local lastRank  = lastInfo["rank"];

    local scale = score / lastScore;
    if scale < 0.5 then
        rank = total - (total - lastRank) * score / lastScore * (score + lastScore) / lastScore * 2 / 3;
    else
        rank = lastRank + (total - lastRank) * 4/3 +
            (total - lastRank) * score / lastScore * (2 * score - 6 * lastScore) / lastScore / 3;
    end

    -- 1M以上当做999K
    if rank > 999999 then
        rank = 999999;
    end

    -- 10000以内显示具体名次
    if rank > 9999 then
        rank = math.modf(rank / 1000) * 1000;
        rank = changeNumType(math.modf(rank));
    else
        rank = math.modf(rank)
    end

    return rank;
end